package com.apexwear.apexutils.data;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.apex.bluetooth.callback.GeneralCallback;
import com.apex.bluetooth.callback.TimeCallback;
import com.apex.bluetooth.core.EABleManager;
import com.apex.bluetooth.enumeration.QueryWatchInfoType;
import com.apex.bluetooth.model.EABleSyncTime;

public class TimeData extends ViewModel {
    public MutableLiveData<EABleSyncTime> getTime() {
        MutableLiveData<EABleSyncTime> mutableLiveData = new MutableLiveData<>();
        EABleManager.getInstance().queryWatchInfo(QueryWatchInfoType.sync_time, new TimeCallback() {
            @Override
            public void syncTime(EABleSyncTime eaBleSyncTime) {
                mutableLiveData.postValue(eaBleSyncTime);
            }

            @Override
            public void mutualFail(int i) {
                mutableLiveData.postValue(null);
            }
        });
        return mutableLiveData;
    }

    public MutableLiveData<Boolean> setTime(EABleSyncTime eaBleSyncTime) {
        MutableLiveData<Boolean> mutableLiveData = new MutableLiveData<>();
        EABleManager.getInstance().setTimeSync(eaBleSyncTime, new GeneralCallback() {
            @Override
            public void result(boolean b,int i) {
                mutableLiveData.postValue(b);
            }

            @Override
            public void mutualFail(int i) {
                mutableLiveData.postValue(false);
            }
        });
        return mutableLiveData;
    }
}
